<template #default="scope">
  <!-- <el-form ref="userRef" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="用户昵称" prop="nickName">
         <el-input v-model="form.nickName" maxlength="30" />
      </el-form-item>
      <el-form-item label="手机号码" prop="phonenumber">
         <el-input v-model="form.phonenumber" maxlength="11" />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
         <el-input v-model="form.email" maxlength="50" />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
         <el-radio-group v-model="form.sex">
            <el-radio label=0>男</el-radio>
            <el-radio label=1>女</el-radio>
            <el-radio label=2>保密</el-radio>
         </el-radio-group>
      </el-form-item>
      <el-form-item>
      <el-button type="primary" @click="submit">保存</el-button>
      <el-button type="danger" @click="close">关闭</el-button>
      </el-form-item>
   </el-form> -->
  <el-form ref="userRef" :model="form" :rules="rules" label-width="80px">
    <el-row>
      <el-col :span="12">
        <el-form-item label="账号" prop="userName">
          <el-input v-model="form.userName" placeholder="账号" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="姓名" prop="nickName">
          <el-input v-model="form.nickName" placeholder="用户姓名" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="用户性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择用户性别">
            <el-option v-for="dict in sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="12">
        <el-form-item label="意向等级" prop="level">
          <el-select v-model="form.level" placeholder="意向等级">
            <el-option v-for="(dict,index) in levele" :key="index" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
      </el-col>

      <el-col :span="12">
        <el-form-item label="民族" prop="nation" v-if="form.nation">
          <el-input v-model="form.nation" placeholder="请输入民族" />
        </el-form-item>
      </el-col>
    </el-row>
    <el-col :span="24">
      <el-form-item label-width="82px" label="邮箱" prop="email">
        <el-input v-model="form.email" placeholder="邮箱" clearable :style="{ width: '100%' }"></el-input>
      </el-form-item>
      <el-form-item label-width="82px" label="手机号" prop="phonenumber">
        <el-input v-model="form.phonenumber" placeholder="手机号" clearable :style="{ width: '100%' }" maxlength="11"
          oninput="value=value.replace(/^\D*([0-9]\d*\.?\d{0})?.*$/,'$1')"></el-input>
      </el-form-item>
      <el-form-item label-width="82px" label="身份证号" prop="staffNumber" v-if="form.staffNumber">
        <el-input v-model="form.staffNumber" placeholder="身份证号" clearable :style="{ width: '100%' }" maxlength="18"
          oninput="value=value.replace(/^\D*([0-9]\d*\.?\d{0})?.*$/,'$1')"></el-input>
      </el-form-item>
      <el-form-item label-width="82px" label="银行卡号" prop="cardNumber" v-if="form.cardNumber">
        <el-input v-model="form.cardNumber" placeholder="银行卡号" clearable :style="{ width: '100%' }" maxlength="19"
          oninput="value=value.replace(/^\D*([0-9]\d*\.?\d{0,0})?.*$/,'$1')"></el-input>
      </el-form-item>
    </el-col>
    <el-form-item>
      <el-button type="primary" @click="submit">保存</el-button>
      <el-button type="danger" @click="close">关闭</el-button>
    </el-form-item>
  </el-form>

</template>

<script setup name="Humanresource">
import { updateUserProfile } from "@/api/system/user";
const { proxy } = getCurrentInstance();
// const {  level } = proxy.useDict('level');


const props = defineProps({
  user: {
    type: Object
  }
});

const levele = [
  { label: "随时到岗", value: 0 },
  { label: "积极求职", value: 1 },
  { label: "考虑机会", value: 3 },
  { label: "暂不考虑", value: 4 },
]

const sys_user_sex = [
  { label: "男", value: 0 },
  { label: "女", value: 1 },
  { label: "保密", value: 2 },
]


const form = ref({});
const rules = ref({
  nickName: [{ required: true, message: "用户姓名不能为空", trigger: "blur" }],
  email: [{ required: true, message: "邮箱地址不能为空", trigger: "blur" }, { type: "email", message: "请输入正确的邮箱地址", trigger: ["blur", "change"] }],
  phonenumber: [{ required: true, message: "手机号码不能为空", trigger: "blur" }, { pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "请输入正确的手机号码", trigger: "blur" }],
  staffNumber: [{ required: true, message: "身份证号不能为空", trigger: "blur" }],
  cardNumber: [{ required: true, message: "银行卡号不能为空", trigger: "blur" }],
  userName: [{ required: true, message: "账号不能为空", trigger: "blur" }],
  nation: [{ required: true, message: "民族不能为空", trigger: "blur" }],
});

function reset() {
  form.value = {
    userId: null,
    userName: null,
    nickName: null,
    userType: null,
    email: null,
    phonenumber: null,
    sex: null,
    avatar: null,
    password: null,
    status: null,
    delFlag: null,
    loginIp: null,
    loginDate: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    remark: null,
    level: null,
    idleState: null,
    deptId: null,
    staffNumber: null,
    nation: null,
    wages: null,
    flag: null,
    cardNumber: null,
    deptName: null,
    postId: null,
    roleId: null,
    postName: null,
    roleName: null,
    amount: null,
    number: null,
    postIds: [],
    parentName: null
  };
  proxy.resetForm("userRef");
}

/** 提交按钮 */
function submit() {
  proxy.$refs.userRef.validate(valid => {
    if (valid) {
      updateUserProfile(form.value).then(response => {
        proxy.$modal.msgSuccess("修改成功");
        props.user.phonenumber = form.value.phonenumber;
        props.user.email = form.value.email;
        props.user.sex = form.value.sex;
      });
    }
  });
};

/** 关闭按钮 */
function close() {
  proxy.$tab.closePage();
};

// 回显当前登录用户信息
watch(() => props.user, user => {
  if (user) {
    form.value = {
      nickName: user.nickName,
      userName: user.userName,
      phonenumber: user.phonenumber,
      email: user.email,
      sex: user.sex,
      nation: user.nation,
      staffNumber: user.staffNumber,
      cardNumber: user.cardNumber,
      level: user.level
    };
  }
}, { immediate: true });
</script>
